package hg.demo.mybatis.plus.generator;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class MyBatisPlusGenerator {
    public static void main(String[] args) {
        System.out.println("------------------");
        System.out.println("--------开始生成----------");
        AutoGenerator autoGenerator = initAutoGenerator();
        autoGenerator.execute();
        System.out.println("--------生成完成----------");
        System.out.println("------------------");
    }

    /**
     * 初始化-生成器
     */
    private static AutoGenerator initAutoGenerator() {
        AutoGenerator autoGenerator = new AutoGenerator();
        autoGenerator.setGlobalConfig(initGlobalConfig());
        autoGenerator.setDataSource(iniDataSourceConfig());
        autoGenerator.setStrategy(initStrategyConfig());
        autoGenerator.setPackageInfo(initPackageConfig());
        return autoGenerator;
    }

    /**
     * 初始化-全局配置
     * @return
     */
    public static GlobalConfig initGlobalConfig() {
        GlobalConfig config = new GlobalConfig();
        //config.setAuthor("guoqifei");
        config.setAuthor("hgSuper");
        config.setBaseResultMap(false);
        // 生成路径
        config.setOutputDir("G:\\tmp");
        config.setIdType(IdType.INPUT);
        config.setDateType(DateType.ONLY_DATE);
        config.setFileOverride(true);
        return config;
    }


    static String[] tables = new String[] {"t_alarm_asw"};

    //static String parentPackage = "com.citcc4.dbviews.snDate";
    // 光储云-mysql
    static String parentPackage = "com.citcc4.business.thirdalarm.asw";
    // 光储云-td
    //static String parentPackage = "com.citcc4.gfy.td.service.business.stacache";
    //static String parentPackage = "com.ruoyi.hg.business";

    // 08项目
    //static String parentPackage = "com.citcc4.datacenter.iot.business.weatherstation";
    // eladmin
    //static String parentPackage = "cn.hg.framework.eladmin.business.transfertxt";


    //static String parentPackage = "com.citcc4.oam.service.dbview";
    //static String parentPackage = "com.citcc.echarge.system.mybatisplus.mock.chargeNum";
    //static String parentPackage = "cn.hg";


    //static String JDBC_URL = "jdbc:mysql://localhost:3307/eladmin?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=UTC";
    //static String JDBC_URL = "jdbc:mysql://localhost:3307/citcc4-jkzx-dev?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=UTC";
    static String JDBC_URL = "jdbc:mysql://192.168.100.146:3306/citcc4-gfy-test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
    //static String JDBC_URL = "jdbc:mysql://192.168.100.39:3307/citcc4-datacenter?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
    //static String JDBC_URL = "jdbc:mysql://39.98.75.137:3306/test_eladmindb?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false";
    //static String JDBC_URL = "jdbc:mysql://127.0.0.1:3307/blegps?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false";
    static String JDBC_USER = "root";
    //static String JDBC_USER = "test_eladmin";
    //static String JDBC_PWD = "root";
    //static String JDBC_PWD = "SHzPRexK";
    static String JDBC_PWD = "XziIdyifbqPuZGiI";

    static String tablePrefix = "t_";
    //static String tablePrefix = "hg_";
    //static String tablePrefix = "hg_yingyang_";
    //static String tablePrefix = "v_";
    //static String tablePrefix = "t_jk_";
    //static String tablePrefix = "v_jk_";

    /**
     * 初始化-包配置
     * @return
     */
    private static PackageConfig initPackageConfig() {
        //String parentPackage = "com.citcc4.business.tenantPac";
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent(parentPackage);
        packageConfig.setService("service");
        packageConfig.setServiceImpl("service.impl");
        packageConfig.setMapper("mapper");
        packageConfig.setXml("mapper.xml");
        packageConfig.setController("controller");
        packageConfig.setEntity("entity");
        return packageConfig;
    }

    /**
     * 初始化-数据库连接
     * @return
     */
    private static DataSourceConfig iniDataSourceConfig() {
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        //dataSourceConfig.setDbType(DbType.MYSQL);
        dataSourceConfig.setDbType(DbType.MYSQL);
        dataSourceConfig.setUrl(JDBC_URL);
        //dataSourceConfig.setUrl("jdbc:mysql://192.168.100.39:3306/citcc4-gfy?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8");
        //dataSourceConfig.setUrl("jdbc:mysql://192.168.100.39:3306/citcc4-gfy-test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8");
        //dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/eladmin?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=UTC");
        //dataSourceConfig.setUrl("jdbc:mysql://127.0.0.1:3306/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8");
        //dataSourceConfig.setUrl("jdbc:mysql://127.0.0.1:3307/blegps?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8");
        //dataSourceConfig.setUrl("jdbc:mysql://127.0.0.1:3307/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8");
        //dataSourceConfig.setUrl("jdbc:mysql://192.168.100.39:3306/citcc4-lvnengchong-test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8");

        //dataSourceConfig.setUrl("jdbc:mysql://192.168.100.134:3306/citcc4-oam-dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8");
        dataSourceConfig.setUsername(JDBC_USER);
        //dataSourceConfig.setPassword("XziIdyifbqPuZGiI");
        dataSourceConfig.setPassword(JDBC_PWD);
        //dataSourceConfig.setPassword("citcc4");
        //dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSourceConfig.setDriverName("com.mysql.jdbc.Driver");
        return dataSourceConfig;
    }

    /**
     * 初始化-生成策略
     * @return
     */
    private static StrategyConfig initStrategyConfig() {
        // 表名
        //String[] tables = new String[] {"t_tenant_pac"};
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setCapitalMode(true)
                .setEntityLombokModel(true)
                // 删除前缀
                .setTablePrefix(tablePrefix)
                .setNaming(NamingStrategy.underline_to_camel)
                .setInclude(tables);
        return strategyConfig;
    }
}
